using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SwinMessengerLibrary;

namespace SwinMessenger
{
    public partial class ChatForm : Form
    {
        Contact _Contact;

        public Contact Contact
        {
            get { return _Contact; }
        }

        ContactPanel _ContactPanel;

        public ChatForm(Contact contact)
            : this()
        {
            _Contact = contact;

            _ContactPanel = new ContactPanel(this, _Contact);
            _ContactPanel.Dock = DockStyle.Fill;
            _ContactPanel.OnMessaging += new EventHandler(_ContactPanel_OnMessaging);

            this.Text = _Contact.Id;
            this.Controls.Add(_ContactPanel);

        }

        void _ContactPanel_OnMessaging(object sender, EventArgs e)
        {
            if (e is MessageEventArgs)
            {
                MessageEventArgs mea = (MessageEventArgs)e;
                string state = mea.State;
                if (state.ToLower().Equals("composing"))
                {
                    this.Text = _Contact.Id + " is entering text.";
                }
                else
                {
                    this.Text = _Contact.Id;
                }
            }
        }

        protected ChatForm()
        {
            InitializeComponent();
        }

        private void ChatForm_Load(object sender, EventArgs e)
        {

        }

        private void ChatForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            _Contact.CanClose = true;
        }
    }
}